
how to define:

class CLASSNAME : entity
{
	float foo;
	float bar;
	virtual void() somevirtualfunction;
	static void() somestaticfunction;
};
void() CLASSNAME::somestaticfunction = 
{
	print(sprint("huzzah! foo is %f\n", foo));
};
void() CLASSNAME::somevirtualfunction; = 
{
	print("wahoo!\n");
};


the above defines a class called CLASSNAME which inherits from the basic entity type.
it has one float member called foo.
it has one virtual function called somevirtualfunction.
it has one static function caleld somestaticfunction.

okay, now I really should explain what a 'virtual' function is and what a 'static' function is...
Here goes...
static functions defined within classes are basically regular functions, just with a different namespace (ie: they're only different from vanilla qc functions due to the CLASSNAME:: part at the start of their name.
virtual functions are more interesting. These are basically like .think or .touch from vanilla qc. the only difference is that they're automatically set up by the constructor, and class-specific. They are both a field and a static function.


To spawn an entity, there are two methods.
method 1:
return spawn(CLASSNAME, foo:5, bar:4);
method 2:
entity self = spawn();
((CLASSNAME)self).foo = 5;
((CLASSNAME)self).bar = 4;
spawnfunc_CLASSNAME();
return self;
Both methods are identical. The first method is the 'proper' way to spawn classes from qc. The second method has issues with types and is provided only for map compatibility and documented here only for mapping purposes.
Note the spawnfunc_ prefix. This will work out of the box in FTE and DP, but other engines will need a void()CLASSNAME={spawnfunc_CLASSNAME();}; wrapper. Additionally maps are only able to use fields from the basic entity class, as the engine is not aware of classes/class namespaces/namespace mangling.

Constructors.
void() CLASSNAME::CLASSNAME =
{
	print("in constructor for CLASSNAME\n");
};
Constructors return nothing and never accept any arguments. All arguments must come via entity fields. This is consistant with mapping, as demonstrated by examples above.
You should normally not call constructors directly as this will not reset the virtual functions, this is not a way to change an entity from one class to another.
Internal info:
spawnfunc_CLASSNAME is an auto-generated function that sets up the virtual functions and then calls the constructor of the class and its parent classes. It will not clear out any fields, which reduces the value of directly calling it, but it is still useful for mapping or legacy(like player entity non-recreation) purposes.

Inheritance. This is where the virtual stuff really shines.
class otherclass : CLASSNAME
{
	static void() somestaticfunction =
	{
		print("plop\n");
	};
	virtual void() somevirtualfunction =
	{
		foo = 3;				//identical to this.foo = 3;
		somestaticfunction();			//prints 'plop'
		CLASSNAME::somestaticfunction();	//prints something celebratory about foo.
		CLASSNAME::somevirtualfunction();	//prints wahoo - using an explicit namespace avoiding the use of virtual functions.
		super::somevirtualfunction();		//prints wahoo - 'super' is a shortcut for the class this one inherits from, so the same as the above line.
	};
};
Multiple inheritance isn't supported. That stuff is crazy.

polymorphism:
CLASSNAME bob;
bob = spawn(otherclass);	//one class
bob.somevirtualfunction(); 	//prints 4 lines of spam.
bob = spawn(CLASSNAME);		//the original type
bob.somevirtualfunction();	//print just 'wahoo'.
You can pass your object around and use the various virtual methods provided by the 'root' class, and you'll get the replacement behaviour provided by the child classes instead. Which is handy. Means you don't have to check if its a soldier, shambler, etc. Just call a function and let it do its own work, and if it didn't provide that function you'll just get the parent's function instead. hurrah.

Fields...
As you may have noted already, 'foo' used in a class is automatically taken to be 'this.foo' instead. This messes up the find builtin and related stuff quite a lot. You can pass either 'this::classname', but if its a generic entity field just '::classname' will do the job.

